package com.example.myapplication.ui.fragment;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.example.myapplication.R;
import com.example.myapplication.bean.ImageBean;
import com.example.myapplication.util.ContentUtils;
import com.squareup.picasso.Picasso;

import java.io.Serializable;

/**
 * A simple {@link Fragment} subclass.
 */
public class ItemImageFragment extends Fragment {

    ImageView picIv;
    TextView titleTv,painterTv,summaryTv,authorTv;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view =  inflater.inflate(R.layout.fragment_item_image, container, false);
        initView(view);
        Bundle bundle = getArguments();
        ImageBean.ResultBean bean = (ImageBean.ResultBean) bundle.getSerializable("image");
//        加载数据
        String imageURL = bean.getImage();
        if (!TextUtils.isEmpty(imageURL)) {
            imageURL = ContentUtils.PICTURE_DISPLAY_URL+imageURL;
            Picasso.get().load(imageURL).into(picIv);
        }
        titleTv.setText(bean.getTitle());
        summaryTv.setText(bean.getSummary());
        return view;
    }
    /* 初始化控件 */
    private void initView(View view) {
        picIv = view.findViewById(R.id.itemimage_iv);
        titleTv = view.findViewById(R.id.itemimage_tv_title);
        painterTv = view.findViewById(R.id.itemimage_tv_painter);
        summaryTv = view.findViewById(R.id.itemimage_tv_summary);
        authorTv = view.findViewById(R.id.itemimage_tv_author);
    }
}
